package me.firstapp.manage.member;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.JSONObject;

import me.firstapp.common.exception.ServiceException;
import me.firstapp.common.exception.StatusHouse;
import me.firstapp.common.json.SingleObject;
import me.firstapp.common.utils.DateUtils;
import me.firstapp.common.utils.MD5Utils;
import me.firstapp.common.utils.Page;
import me.firstapp.common.utils.ResponseUtils;
import me.firstapp.common.utils.StrUtils;
import me.firstapp.manage.common.BaseManage;
import me.firstapp.manage.utils.BizData4Page;
import me.firstapp.manage.utils.OpenApiUtils;
import me.firstapp.module.weixin.jinbi.JinBiAccountTrace;
import me.firstapp.module.weixin.member.Member;
import me.firstapp.module.weixin.member.SoftFee;
import me.firstapp.module.weixin.order.SpreadOrder;
import me.firstapp.module.weixin.system.Operator;
import me.firstapp.module.weixin.weibi.WeiBiAccountTrace;
import me.firstapp.module.weixin.weibi.WeiBiAccountTrace.ChangeType;
import me.firstapp.service.weixin.account.JinBiAccountService;
import me.firstapp.service.weixin.account.JinBiAccountTraceService;
import me.firstapp.service.weixin.account.WeiBiAccountService;
import me.firstapp.service.weixin.account.WeiBiAccountTraceService;
import me.firstapp.service.weixin.member.MemberService;
import me.firstapp.service.weixin.member.SpreadOrderService;
import me.firstapp.service.weixin.soft.SoftFeeService;
import me.firstapp.service.weixin.system.OperatorService;

@Controller
@RequestMapping(value = "/memberManage")
public class MemberManageAct extends BaseManage {

	@Autowired
	private SoftFeeService softFeeService;

	@Autowired
	private MemberService memberService;

	@Autowired
	private WeiBiAccountTraceService weiBiAccountTraceService;

	@Autowired
	private WeiBiAccountService weiBiAccountService;

	@Autowired
	private JinBiAccountTraceService jinBiAccountTraceService;

	@Autowired
	private JinBiAccountService jinBiAccountService;

	@Autowired
	private OperatorService operatorService;

	@Autowired
	private SpreadOrderService spreadOrderService;

	@Autowired
	private RestTemplate restTemplate;

	@ResponseBody
	@RequestMapping(value = "/findCardFeePage.do", method = RequestMethod.POST)
	public void findCardFeePage(@RequestParam Map<String, Object> conditions, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						searchParams.put(key, jsonObject.get(key));
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<SoftFee> cardFeePage = softFeeService.findSoftFeePage(pageNo, iDisplayLength, searchParams,
						mDataProp, sSortDir_0);

				BizData4Page<SoftFee> bizData4Page = new BizData4Page<SoftFee>();
				bizData4Page.setUserdata(conditions);
				if (cardFeePage != null) {
					bizData4Page.setPage(cardFeePage.getPageNo());
					bizData4Page.setPagesize(cardFeePage.getPageSize());
					bizData4Page.setRecords(cardFeePage.getEntityCount());
					bizData4Page.setRows(new ArrayList<SoftFee>(cardFeePage.getEntities()));
					bizData4Page.setTotal(cardFeePage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/addCardFee.do", method = RequestMethod.POST)
	public void addCardFee(Integer vipLevel, Integer validDays, BigDecimal price, BigDecimal chiefBaseVipJinBi,
			BigDecimal chiefHighVipJinBi, BigDecimal chiefBaseVipPoint, BigDecimal chiefHighVipPoint, String remark,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			softFeeService.executeAddSoftFee(vipLevel, validDays, price, chiefBaseVipJinBi, chiefHighVipJinBi,
					chiefBaseVipPoint, chiefHighVipPoint, remark);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateCardFee.do", method = RequestMethod.POST)
	public void updateCardFee(Long id, Integer vipLevel, Integer validDays, BigDecimal price,
			BigDecimal chiefBaseVipJinBi, BigDecimal chiefHighVipJinBi, BigDecimal chiefBaseVipPoint,
			BigDecimal chiefHighVipPoint, String remark, HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			softFeeService.executeUpdateSoftFee(id, vipLevel, validDays, price, chiefBaseVipJinBi, chiefHighVipJinBi,
					chiefBaseVipPoint, chiefHighVipPoint, remark);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findMemberPage.do", method = RequestMethod.POST)
	public void findMemberPage(@RequestParam Map<String, Object> conditions, Integer vipLevel, String partnerOpenId,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			String startTime = null;
			String endTime = null;
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						if ("registerTime".equals(key)) {
							// 日期范围判断
							String registerTimes = (String) jsonObject.get(key);
							if (registerTimes.contains(",")) {
								String[] registerTimesArra = registerTimes.split(",");
								startTime = registerTimesArra[0];
								endTime = registerTimesArra[1];
								if ("0".equals(startTime)) {
									startTime = null;
								}
								if ("0".equals(endTime)) {
									endTime = null;
								}
							}
						} else {
							searchParams.put(key, jsonObject.get(key));
						}
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<Member> memberPage = memberService.findMemberPage(pageNo, iDisplayLength, searchParams, mDataProp,
						sSortDir_0,
						StrUtils.isNULL(startTime) ? null : DateUtils.getDateFromTimeStamp(startTime, "yyyy-MM-dd"),
						StrUtils.isNULL(endTime) ? null : DateUtils.getDateFromTimeStamp(endTime, "yyyy-MM-dd"),
						vipLevel, partnerOpenId);

				BizData4Page<Member> bizData4Page = new BizData4Page<Member>();
				bizData4Page.setUserdata(conditions);
				if (memberPage != null) {
					bizData4Page.setPage(memberPage.getPageNo());
					bizData4Page.setPagesize(memberPage.getPageSize());
					bizData4Page.setRecords(memberPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<Member>(memberPage.getEntities()));
					bizData4Page.setTotal(memberPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/updateMember.do", method = RequestMethod.POST)
	public void updateMember(String openId, String mobile, String weixin, Integer status, Integer followStatus,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			memberService.executeUpdateMember(openId, mobile, weixin, status, followStatus);
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findWeiBiAccountTracePage.do", method = RequestMethod.POST)
	public void findWeiBiAccountTracePage(@RequestParam Map<String, Object> conditions, String openId,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			String startTime = null;
			String endTime = null;
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						if ("changeTime".equals(key)) {
							// 日期范围判断
							String registerTimes = (String) jsonObject.get(key);
							if (registerTimes.contains(",")) {
								String[] registerTimesArra = registerTimes.split(",");
								startTime = registerTimesArra[0];
								endTime = registerTimesArra[1];
								if ("0".equals(startTime)) {
									startTime = null;
								}
								if ("0".equals(endTime)) {
									endTime = null;
								}
							}
						} else {
							searchParams.put(key, jsonObject.get(key));
						}
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<WeiBiAccountTrace> weiBiAccountTracePage = weiBiAccountTraceService.findWeiBiAccountTracePage(
						openId, pageNo, iDisplayLength, searchParams, mDataProp, sSortDir_0,
						StrUtils.isNULL(startTime) ? null : DateUtils.getDateFromTimeStamp(startTime, "yyyy-MM-dd"),
						StrUtils.isNULL(endTime) ? null : DateUtils.getDateFromTimeStamp(endTime, "yyyy-MM-dd"));

				BizData4Page<WeiBiAccountTrace> bizData4Page = new BizData4Page<WeiBiAccountTrace>();
				bizData4Page.setUserdata(conditions);
				if (weiBiAccountTracePage != null) {
					bizData4Page.setPage(weiBiAccountTracePage.getPageNo());
					bizData4Page.setPagesize(weiBiAccountTracePage.getPageSize());
					bizData4Page.setRecords(weiBiAccountTracePage.getEntityCount());
					bizData4Page.setRows(new ArrayList<WeiBiAccountTrace>(weiBiAccountTracePage.getEntities()));
					bizData4Page.setTotal(weiBiAccountTracePage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/tzWeibi.do", method = RequestMethod.POST)
	public void tzWeibi(Long weiBiAccountId, Integer type, BigDecimal changeValue, String name, String password,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			Operator operator = operatorService.findOperatorByName(name);
			if (null == operator) {
				throw new ServiceException("error", "操作员不存在");
			}
			if (!MD5Utils.verify(password, operator.getPassword())) {
				throw new ServiceException("error", "密码不正确");
			}
			ChangeType changeType = ChangeType.HANDLE_ADD;
			if (type == 0) {
				changeType = ChangeType.HANDLE_SUB;
			} else if (type == 1) {
				changeType = ChangeType.HANDLE_ADD;
			}
			WeiBiAccountTrace weiBiAccountTrace = weiBiAccountService.executeTzWeiBiAccount(weiBiAccountId, changeType,
					changeValue);
			try {
				OpenApiUtils.sendWeiBiChangeMessage(restTemplate, weiBiAccountTrace.getId());
			} catch (Exception e) {
				e.printStackTrace();
			}
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findJinBiAccountTracePage.do", method = RequestMethod.POST)
	public void findJinBiAccountTracePage(@RequestParam Map<String, Object> conditions, String openId,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			String startTime = null;
			String endTime = null;
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						if ("changeTime".equals(key)) {
							// 日期范围判断
							String registerTimes = (String) jsonObject.get(key);
							if (registerTimes.contains(",")) {
								String[] registerTimesArra = registerTimes.split(",");
								startTime = registerTimesArra[0];
								endTime = registerTimesArra[1];
								if ("0".equals(startTime)) {
									startTime = null;
								}
								if ("0".equals(endTime)) {
									endTime = null;
								}
							}
						} else {
							searchParams.put(key, jsonObject.get(key));
						}
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<JinBiAccountTrace> jinBiAccountTracePage = jinBiAccountTraceService.findJinBiAccountTracePage(
						openId, pageNo, iDisplayLength, searchParams, mDataProp, sSortDir_0,
						StrUtils.isNULL(startTime) ? null : DateUtils.getDateFromTimeStamp(startTime, "yyyy-MM-dd"),
						StrUtils.isNULL(endTime) ? null : DateUtils.getDateFromTimeStamp(endTime, "yyyy-MM-dd"));

				BizData4Page<JinBiAccountTrace> bizData4Page = new BizData4Page<JinBiAccountTrace>();
				bizData4Page.setUserdata(conditions);
				if (jinBiAccountTracePage != null) {
					bizData4Page.setPage(jinBiAccountTracePage.getPageNo());
					bizData4Page.setPagesize(jinBiAccountTracePage.getPageSize());
					bizData4Page.setRecords(jinBiAccountTracePage.getEntityCount());
					bizData4Page.setRows(new ArrayList<JinBiAccountTrace>(jinBiAccountTracePage.getEntities()));
					bizData4Page.setTotal(jinBiAccountTracePage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@RequestMapping(value = "/tzJinbi.do", method = RequestMethod.POST)
	public void tzJinbi(Long jinBiAccountId, Integer type, BigDecimal changeValue, String name, String password,
			HttpServletRequest request, HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<>();
		try {
			Operator operator = operatorService.findOperatorByName(name);
			if (null == operator) {
				throw new ServiceException("error", "操作员不存在");
			}
			if (!MD5Utils.verify(password, operator.getPassword())) {
				throw new ServiceException("error", "密码不正确");
			}
			me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType changeType = me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.HANDLE_ADD;
			if (type == 0) {
				changeType = me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.HANDLE_SUB;
			} else if (type == 1) {
				changeType = me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.HANDLE_ADD;
			} else if (type == 2) {
				changeType = me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.RECHARGE_ADD;
			} else if (type == 3) {
				changeType = me.firstapp.module.weixin.jinbi.JinBiAccountTrace.ChangeType.FRIGHT_RETURN_ADD;
			}

			JinBiAccountTrace jinBiAccountTrace = jinBiAccountService.executeTzJinBiAccount(jinBiAccountId, changeType,
					changeValue);
			try {
				OpenApiUtils.sendJinBiChangeMessage(restTemplate, jinBiAccountTrace.getId());
			} catch (Exception e) {
				e.printStackTrace();
			}
			result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}

	@ResponseBody
	@RequestMapping(value = "/findSpreadOrderPage.do", method = RequestMethod.POST)
	public void findSpreadOrderPage(@RequestParam Map<String, Object> conditions, HttpServletRequest request,
			HttpServletResponse response) {
		SingleObject<Object> result = new SingleObject<Object>();
		try {
			// 搜索条件
			Map<String, Object> searchParams = new HashMap<>();
			String sSearchJson = (String) conditions.get("sSearch");
			String startTime = null;
			String endTime = null;
			if (StrUtils.isNotNULL(sSearchJson)) {
				JSONObject jsonObject = JSONObject.parseObject(sSearchJson);
				if (jsonObject != null) {
					Set<String> keySet = jsonObject.keySet();
					for (String key : keySet) {
						if ("createTime".equals(key)) {
							// 日期范围判断
							String registerTimes = (String) jsonObject.get(key);
							if (registerTimes.contains(",")) {
								String[] registerTimesArra = registerTimes.split(",");
								startTime = registerTimesArra[0];
								endTime = registerTimesArra[1];
								if ("0".equals(startTime)) {
									startTime = null;
								}
								if ("0".equals(endTime)) {
									endTime = null;
								}
							}
						} else {
							searchParams.put(key, jsonObject.get(key));
						}
					}
				}
			}
			// 排序字段
			String mDataProp = "mDataProp_" + conditions.get("iSortCol_0");
			mDataProp = conditions.get(mDataProp).toString().replace("Str", "");
			// 排序方式
			String sSortDir_0 = (String) conditions.get("sSortDir_0");
			// 页容
			String iDisplayLengthStr = (String) conditions.get("iDisplayLength");
			// 是开始数不是当前页数...
			String iDisplayStartStr = (String) conditions.get("iDisplayStart");
			if (StrUtils.isNotNULL(iDisplayLengthStr) && StrUtils.isNotNULL(iDisplayStartStr)) {
				Integer iDisplayLength = Integer.valueOf(iDisplayLengthStr);
				Integer iDisplayStart = Integer.valueOf(iDisplayStartStr);
				// 当前页数
				Integer pageNo = iDisplayStart / iDisplayLength + 1;
				Page<SpreadOrder> spreadOrderPage = spreadOrderService.findSpreadOrderPage(pageNo, iDisplayLength,
						searchParams, mDataProp, sSortDir_0,
						StrUtils.isNULL(startTime) ? null : DateUtils.getDateFromTimeStamp(startTime, "yyyy-MM-dd"),
						StrUtils.isNULL(endTime) ? null : DateUtils.getDateFromTimeStamp(endTime, "yyyy-MM-dd"));

				BizData4Page<SpreadOrder> bizData4Page = new BizData4Page<SpreadOrder>();
				bizData4Page.setUserdata(conditions);
				if (spreadOrderPage != null) {
					bizData4Page.setPage(spreadOrderPage.getPageNo());
					bizData4Page.setPagesize(spreadOrderPage.getPageSize());
					bizData4Page.setRecords(spreadOrderPage.getEntityCount());
					bizData4Page.setRows(new ArrayList<SpreadOrder>(spreadOrderPage.getEntities()));
					bizData4Page.setTotal(spreadOrderPage.getEntityCount());
				}

				result.setObject(bizData4Page);
				result.setStatusObject(StatusHouse.COMMON_STATUS_OK);
			}
		} catch (ServiceException e) {
			e.printStackTrace();
			result.setStatusObject(e.getStatusObject());
		} catch (Exception e) {
			e.printStackTrace();
			result.setStatusObject(StatusHouse.COMMON_STATUS_ERROR);
		}
		ResponseUtils.renderJson(response, result);
	}
}
